package com.heu.blood.charge.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heu.blood.charge.entity.ChargeItemEntity;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.Query;

import com.heu.blood.charge.dao.ChargeDao;
import com.heu.blood.charge.entity.ChargeEntity;
import com.heu.blood.charge.service.ChargeService;


@Service
public class ChargeServiceImpl extends ServiceImpl<ChargeDao, ChargeEntity> implements ChargeService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        //
        ChargeEntity entity = new ChargeEntity();

        if(Strings.isNotBlank((String) params.get("patientId")))
            entity.setPatientId((String) params.get("patientId"));
        if(Strings.isNotBlank((String) params.get("chargeId")))
            entity.setChargeId((String) params.get("chargeId"));
        if(Strings.isNotBlank((String) params.get("isReturn")))
            entity.setIsReturn((Integer) params.get("isReturn"));
        if(Strings.isNotBlank((String) params.get("isReturn")))
            entity.setIsReturn(Integer.valueOf((String) params.get("isReturn")));


        LambdaQueryWrapper<ChargeEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Strings.isNotBlank((String) entity.getPatientId()),ChargeEntity::getPatientId,entity.getPatientId())
                .eq(Strings.isNotBlank(entity.getChargeId()),ChargeEntity::getChargeId,entity.getChargeId())
                .eq(entity.getIsReturn() != null,ChargeEntity::getIsReturn,entity.getIsReturn())
                .eq(ChargeEntity::getIfShow,1);


        IPage<ChargeEntity> page = this.page(
                new Query<ChargeEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}